﻿using System;
using System.Collections.Generic;
using Relocation.Service;
using System.Linq;

using System.Linq.Expressions;
namespace Relocation.Data
{
	public partial class Relocatees_House
	{
		/// <summary>
		/// 房款总计.
		/// </summary>
		/// <value>The total1.</value>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public global::System.Nullable<decimal> total1
		{
			get
			{
				return this.money1 + this.money2 + this.money3;
			}
		}

		static public string GetPropName(Expression<Func<Relocatees_House, object>> expr)
		{
			switch (expr.Body.NodeType)
			{
				case ExpressionType.MemberAccess:
					return ((MemberExpression)expr.Body).Member.Name;
				case ExpressionType.Convert:
					return ((MemberExpression)((UnaryExpression)expr.Body).Operand).Member.Name;
				default:
					return null;
			}
		}

		/// <summary>
		/// 货币化安置款冲抵后实收.
		/// </summary>
		/// <value>The total2.</value>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public global::System.Nullable<decimal> total2
		{
			get
			{
				if (!this.RelocateeReference.IsLoaded)
					this.RelocateeReference.Load();
				if (this.Relocatee == null)
					return 0;
				if (this.Relocatee.payment == null)
					this.Relocatee.payment = 0;
				if (this.Relocatee.persons.HasValue && this.Relocatee.persons > 0)
					return this.total1 + this.money4 + this.money5 - this.Relocatee.payment * this.persons / this.Relocatee.persons;
				else
					return this.total1 + this.money4 + this.money5 - this.Relocatee.payment;
			}
		}


		/// <summary>
		/// 安置房号.
		/// </summary>
		/// <value>The housecode.</value>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public string housecode
		{
			get
			{
				return this.House == null ? string.Empty : this.House.house_code;
			}
		}

		/// <summary>
		/// 安置房面积.
		/// </summary>
		/// <value>The House_HouseArea.</value>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public global::System.Nullable<decimal> House_HouseArea
		{
			get
			{
				return this.House == null ? 0 : this.House.area1;
			}
		}

		/// <summary>
		/// Gets .
		/// </summary>
		/// <value></value>
		/// <remarks></remarks>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public global::System.Nullable<int> areaType
		{
			get
			{
				return this.House == null ? 0 : this.House.areatype;
			}
		}

		/// <summary>
		/// 储藏室号.
		/// </summary>
		/// <value>The storecode.</value>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public string storecode
		{
			get
			{
				return this.House == null ? string.Empty : this.House.storeroom;
			}
		}

		/// <summary>
		/// 安置房地区.
		/// </summary>
		/// <value>The district.</value>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public string district
		{
			get
			{
				return this.House == null ? string.Empty : this.House.district;
			}
		}

		/// <summary>
		/// 储藏室面积.
		/// </summary>
		/// <value>The House_StoreArea.</value>
		[global::System.Runtime.Serialization.DataMemberAttribute()]
		public global::System.Nullable<decimal> House_StoreArea
		{
			get
			{
				return this.House == null ? 0 : this.House.area2;
			}
		}

		public Relocatees_House()
			: base()
		{
			Dictionary<Type, int> _primaryKeysCache = DataModel.primaryKeysCache;
			lock (_primaryKeysCache)
			{
				int primaryKey = 0;
				if (!_primaryKeysCache.TryGetValue(this.GetType(), out primaryKey))
				{
					using (DataModel model = new DataModel())
					{
						primaryKey = model.Relocatees_House.Any() ? model.Relocatees_House.Max(c => c.relocatees_house_id) : 0;
					}
				}
				_primaryKeysCache[this.GetType()] = primaryKey;
			}
		}
	}


}
